package cn.cs.yangtai.controller;

import cn.cs.yangtai.entity.Blog;
import cn.cs.yangtai.entity.Orderdetails;
import cn.cs.yangtai.entity.vo.OrderVo;
import cn.cs.yangtai.entity.vo.OrderdetailsVo;
import cn.cs.yangtai.entity.vo.PageResult;
import cn.cs.yangtai.entity.vo.ResponsePojo;
import cn.cs.yangtai.service.OrderdetailsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Orderdetails)表控制层
 *
 * @author makejava
 * @since 2024-12-12 09:22:27
 */
@RestController
@CrossOrigin
@RequestMapping("orderdetails")
@Tag(name = "订单详情")
public class OrderdetailsController {
    /**
     * 服务对象
     */
    @Resource
    private OrderdetailsService orderdetailsService;

    /**
     * 分页查询
     *
     * @param cuttentPage 本页
     * @param pageSize    分页大小
     * @return 查询结果
     */
    @GetMapping
    public ResponsePojo<PageResult<OrderdetailsVo>> queryByPage(Integer cuttentPage, Integer pageSize) {
        PageResult<OrderdetailsVo> result=orderdetailsService.queryByPage(cuttentPage,pageSize);
        return ResponsePojo.success(result);
    }

    /**
     * 根据订单查询详情数据
     * @return 对象列表
     */
    @Operation(summary = "查询用户的订单详情")
    @GetMapping("/UserOrderdetails")
    public List<OrderdetailsVo> OrderdetailsVos(Integer orderId) {
        return orderdetailsService.queryByOrderId(orderId);
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<OrderdetailsVo> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.orderdetailsService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Orderdetails> add(Integer dOrderId,Integer dCId,Integer dQuantity,Double dPrice) {
        Orderdetails orderdetails=new Orderdetails();
        orderdetails.setDOrderId(dOrderId);
        orderdetails.setDCId(dCId);
        orderdetails.setDQuantity(dQuantity);
        orderdetails.setDPrice(dPrice);
        return ResponseEntity.ok(this.orderdetailsService.insert(orderdetails));
    }

    /**
     * 编辑数据
     *
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<OrderdetailsVo> edit(Integer dId,Integer dQuantity,Double dPrice) {
        Orderdetails orderdetails=new Orderdetails();
        orderdetails.setDId(dId);
        orderdetails.setDQuantity(dQuantity);
        orderdetails.setDPrice(dPrice);
        return ResponseEntity.ok(this.orderdetailsService.update(orderdetails));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.orderdetailsService.deleteById(id));
    }

}

